package com.yc.game.cms.service.impl;

import com.yc.game.cms.dao.DoubtMapper;
import com.yc.game.cms.pojo.Doubt;
import com.yc.game.cms.service.DoubtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoubtServiceImpl implements DoubtService {
    @Autowired
    private DoubtMapper doubtMapper;

    /**
     * 获取所有的问题和答案
     * @return
     */
    @Override
    public List<Doubt> getAll() {
        return doubtMapper.getAll();
    }

    /**
     * 更新问题
     * @param doubt
     * @return
     */
    @Override
    public int updateDoubt(Doubt doubt) {
        if (doubt.getId() == null) {
            Doubt newDout = new Doubt();
            newDout.setAnswer(doubt.getAnswer());
            newDout.setQuestion(doubt.getQuestion());
            newDout.setStatus(1);
            return doubtMapper.insertSelective(newDout);
        }
        Doubt newDout = new Doubt();
        newDout.setId(doubt.getId());
        newDout.setAnswer(doubt.getAnswer());
        newDout.setQuestion(doubt.getQuestion());
        newDout.setStatus(doubt.getStatus());
        return doubtMapper.updateByPrimaryKeySelective(newDout);
    }

    /**
     * 删除问题
     * @param doubtId
     * @return
     */
    @Override
    public int deleteById(Integer doubtId) {
        return doubtMapper.deleteByPrimaryKey(doubtId);
    }
}
